//
//  LXMessageRepairCarCell.m
//  ZuLinProject
//
//  Created by bancheng on 2022/7/1.
//  Copyright © 2022 LX_App. All rights reserved.
//

#import "LXMessageRepairCarCell.h"
#import "LXMessageRepairCarInfo.h"
#import "LXMessageRepairCarView.h"
#import "LXAccurateFindCarViewController.h"
@interface LXMessageRepairCarCell()
@property(nonatomic)LXMessageRepairCarView *carView;
@end
@implementation LXMessageRepairCarCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        LXMessageRepairCarView *view = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([LXMessageRepairCarView class]) owner:nil options:nil].firstObject;
        view.backgroundColor = UIColor.clearColor;
        self.carView = view;
        [self.carView.repairBtn whenTapped:^{
            [self.delegate didTapMessageCell:self.model];
        }];
        [self.carView.carDeilBtn whenTapped:^{
            
            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            app.model = self.model;
            
            LXAccurateFindCarViewController *vc = [[LXAccurateFindCarViewController alloc] init];
            LXMessageRepairCarInfo *content = (LXMessageRepairCarInfo *)self.model.content;
            NSDictionary *dic = @{
                @"id":content.carModelId,
                @"carBrand":content.carBrand,
                @"carMode":content.carModel,
                @"runPlatfom":content.plaValue,
                @"carType":content.typeValue,
                @"energeType":content.engValue,
                @"floorPrice":content.rentPrice,
                @"endurance":content.endurance,
                @"publishedId":content.carTypeId,
            };
            
            CheLiangModel *mm = [CheLiangModel mj_objectWithKeyValues:dic];
            vc.model = mm;
            vc.fromVc = NSStringFromClass([[BaseViewController getCurrentVC] class]);
            [[BaseViewController getCurrentVC].navigationController pushViewController:vc animated:YES];
        }];
    
        view.frame = CGRectMake(0, 0, 0, 0);
        [self.baseContentView addSubview:view];
    }
    return self;
    
}

+ (CGSize)sizeForMessageModel:(RCMessageModel *)model withCollectionViewWidth:(CGFloat)collectionViewWidth referenceExtraHeight:(CGFloat)extraHeight{
    // 此处加20 是有个时间的高度
    return CGSizeMake(collectionViewWidth, extraHeight > 20 ? 180 + 35 : 180);
    
}
- (void)setDataModel:(RCMessageModel *)model{
    [super setDataModel:model];
 
    
    LXMessageRepairCarInfo *content = (LXMessageRepairCarInfo *)model.content;
    
    self.carView.carBrandLab.text = [NSString stringWithFormat:@"品牌：%@ %@",content.carBrand,content.carModel];
    [self.carView.carBrandLab addAttributes:@{NSForegroundColorAttributeName : ColorWithAAAAAA} forString:@"品牌：" size:12];
    
    self.carView.engLab.text = [NSString stringWithFormat:@"能源：%@",[NSString stringWithNull:content.engLabel]];
    [self.carView.engLab addAttributes:@{NSForegroundColorAttributeName : ColorWithAAAAAA} forString:@"能源：" size:12];
    
    if ([content.engValue intValue] == 1) {
        self.carView.endLab.text = @"续航：-";
    }
    else {
        self.carView.endLab.text = [NSString stringWithFormat:@"续航：%@公里",[NSString stringWithNull:content.endurance]];
    }
        [self.carView.engLab addAttributes:@{NSForegroundColorAttributeName : ColorWithAAAAAA} forString:@"续航：" size:12];
    
    self.carView.rentLab.text = [NSString stringWithFormat:@"租金：%@",[NSString stringWithNull:content.rentPrice]];
    [self.carView.rentLab addAttributes:@{NSForegroundColorAttributeName : ColorWithAAAAAA} forString:@"租金：" size:12];
    
}

@end
